package org.hypnus.e.engine.interceptor.impl;

import org.hypnus.e.engine.interceptor.Interceptor;
import org.hypnus.e.engine.interceptor.InterceptorChain;
import org.hypnus.e.engine.message.EngineContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CostTimeInterceptor implements Interceptor {
	
	private static final Logger logger = LoggerFactory.getLogger(CostTimeInterceptor.class) ;

	@Override
	public void before(InterceptorChain chain, EngineContext sCxt) {
		sCxt.getDataMap().put("startTime", new Long(System.currentTimeMillis()));
		chain.doBeforeInterceptor(sCxt) ;
	}

	@Override
	public void after(InterceptorChain chain, EngineContext sCxt) {
		long cost = System.currentTimeMillis()-(Long)sCxt.getDataMap().get("startTime") ;
		logger.info("service entry ["+sCxt.getServiceEntry()+"] cost time ==>"+cost) ;
	}

}
